#!/usr/bin/env python

import sys
from itertools import groupby
from collections import defaultdict

def main():
    for uniprot_id, grp in groupby((line.strip('\n').split('\t') for line in sys.stdin), key=lambda i: i[0]):
        go = defaultdict(set)
        for uniprot_id, go_id, go_type in grp:
            go[go_type].add(go_id)

        print '%s\t%s' % (uniprot_id, ' '.join('%s:%s' % (go_type, ','.join(sorted(go_ids))) for go_type, go_ids in go.items()))


main()

